package com.ktkq.service.student.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ktkq.dao.student.StudentMapper;
import com.ktkq.service.student.StudentService;
import com.ktkq.util.PageFinder;
import com.ktkq.util.Pageing;
import com.ktkq.util.TimeUtil;
import com.ktkq.util.font.UploadExcel;
import com.ktkq.vo.Student;


@Service("studentService")
@Transactional
public class StudentServiceImpl implements StudentService{

	@Autowired
	StudentMapper studentMapper;
	
	@Override
	public PageFinder<Student> queryList(Pageing pageing) {
		
		PageFinder<Student> pageFinder = new PageFinder<Student>();
		pageFinder.setRowCount(studentMapper.pageCount(pageing)); //获取总记录数
		pageFinder.setDataList(studentMapper.queryList(pageing));
		return pageFinder;
	}

	@Override
	public void insert(Student t) {
		
		studentMapper.insert(t);
	}

	@Override
	public void update(Student t) {
		
		studentMapper.update(t);
	}

	@Override
	public void delete(Student t) {
		
		studentMapper.delete(t);
	}

	@Override
	public List<Student> queryListById(int id) {
		
		return studentMapper.queryById(id);
	}

	@Override
	public List<Student>  UploadExcel(String filePath,Student stu) {
		
		List<Student>  lss = new ArrayList<Student>();
	List<List<String>> list = new UploadExcel(filePath).AnalysisExcel();
	 if(list.size()!=0){
		 String time = new TimeUtil().getTime();
		 for(List<String> ls :list){
			 Student student = new Student();			
				 student.setStuNo(ls.get(0));
				 student.setStuName(ls.get(1));
				 student.setStuClass(stu.getStuClass());
				 student.setAcademy(stu.getAcademy());
				 student.setCourse(stu.getCourse());
				 student.setTime(time);
				 lss.add(student);
			 studentMapper.insert(student); 
		 } 
		
	 }
	
	return lss;
	}
	
}
